package com.azier.kapacitor.script.node;

import com.azier.kapacitor.script.arg.SingleQuotesArg;
import com.azier.kapacitor.script.method.As;
import com.azier.kapacitor.script.method.NonNegative;
import com.azier.kapacitor.script.method.Quiet;
import com.azier.kapacitor.script.method.Unit;
import com.azier.kapacitor.script.node.nodebind.CommonNodeBind;

import java.util.ArrayList;

/**
* 1 * @Author: luoj
* 2 * @Date: 2019/11/8 11:27
* 3
*/

/**
Create a new node that computes the derivative of adjacent points.
**/
/**
创建一个新节点来计算相邻点的导数。
**/
public class DerivativeNode extends AbstractNode implements CommonNodeBind {
    private static final String name = "derivative";

    public DerivativeNode(String field) {
        super(new ArrayList<>(),new ArrayList<>(),name);
        //
        this.args.add(new SingleQuotesArg(field));
    }

    /**
    The new name of the derivative field. Default is the name of the field used when calculating the derivative.
    **/
    /**
    派生字段的新名称。默认值是计算导数时使用的字段名称。
    **/
    public DerivativeNode as(String derivative){
        As as = new As(derivative);
        super.addMethod(as);
        return this;
    }
    /**
    If called the derivative will skip negative results.
    **/
    /**
    如果称为导数，将跳过负面结果。
    **/
    public DerivativeNode nonNegative(){
        NonNegative nonNegative = new NonNegative();
        super.addMethod(nonNegative);
        return this;
    }
    /**
    Suppress all error logging events from this node.
    **/
    /**
    禁止来自此节点的所有错误记录事件。
    **/
    public DerivativeNode quiet(){
        Quiet quiet = new Quiet();
        super.addMethod(quiet);
        return this;
    }
    /**
    The time unit of the resulting derivative value. Default: 1s
    **/
    /**
    得出的微分值的时间单位。默认值：1s
    **/
    public DerivativeNode unit(long interval, String durationLiteral){
        Unit unit = new Unit(interval, durationLiteral);
        super.addMethod(unit);
        return this;
    }

}